package com.roger.uia.helper.util;

import java.io.File;
import java.io.IOException;

import static com.roger.uia.helper.UiBase.mDevice;

@SuppressWarnings("ResultOfMethodCallIgnored")
public class LogUtils {
    private static final String TAG = "Test" + LogUtils.class.getSimpleName();
    private static Process logProcess;

    public static void logcat(String filePath, String logName) {
        try {
            File f = new File(filePath);
            if (!f.exists())  mDevice.executeShellCommand("mkdir -p " + f);
            File file=new File(filePath+logName);
            if(file.exists()) file.delete();
            logProcess=Runtime.getRuntime().exec("logcat -v time >"+ f +"/"+logName);
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }

    public static void stopLogCat(){
        logProcess.destroy();
    }

    public static void delLog(String filePath, String logName){
        File file=new File(filePath+logName);
        if(file.exists()){
            logProcess.destroy();
            file.delete();
        }
    }
}